import cv2
import time

# face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
camera = cv2.VideoCapture(0)

while True:
    
    ret, frame = camera.read()
    if ret:
        #在当前目录保存图片
        cv2.imwrite("photo.jpg", frame)
        #输出图片信息
        print(frame.shape)
        print("拍照成功")
    else:
        print("拍照失败")




    
    # image = cv2.imread('photo.jpg')
    # gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    # faces = face_cascade.detectMultiScale(gray_image, scaleFactor=1.1, minNeighbors=5)
    # #返回画面是否有人脸
    # if len(faces) > 0:
    #     print("有人脸")
    # else:
    #     print("无人脸")

    # #在图片中画出人脸矩形框
    # for (x, y, w, h) in faces:
    #     cv2.rectangle(image, (x,y), (x+w, y+h), (0, 255, 0), 2)
    # #保存图片
    # cv2.imwrite("face.jpg", image)
    

    

